from math import sqrt
import sys


def add(x, y):
    return x + y


def minus(x, y):
    return x - y


def mul(x, y):
    return x * y


def div(x, y):
    if y == 0:
        print('除数不能为0,请重新运行本程序')
        sys.exit(0)
    return x / y


def power(x, y):
    return x ** y


def quotient(x, y):
    return x // y


def mod(x, y):
    return x % y


def str_to_num(x):
    try:
        eval(x)
    except NameError:
        print('请不要输入字符串,并重新运行本程序')
        return 'error'
    else:
        return eval(x)



if __name__ == "__main__":
    print('这是一个简单的计算器，可以计算加减乘除商余幂\n')

    temp1 = input('请输入待计算的第一个数字\n')
    first_num = str_to_num(temp1)
    if first_num == 'error':
        sys.exit(0)

    temp2 = input('请输入待计算的第二个数字\n')
    second_num = str_to_num(temp2)
    if second_num == 'error':
        sys.exit(0)

    Operator = input('请输入操作符#汉字或数学字符#\n')
    if Operator == '+' or Operator == '加':
        answer = add(first_num, second_num)
        print(first_num, ' + ', second_num, ' = ', answer)

    elif Operator == '-' or Operator == '减':
        answer = minus(first_num, second_num)
        print(first_num, ' - ', second_num, ' = ', answer)

    elif Operator == '*' or Operator == '乘':
        answer = mul(first_num, second_num)
        print(first_num, ' * ', second_num, ' = ', answer)

    elif Operator == '/' or Operator == '除':
        answer = div(first_num, second_num)
        print(first_num, ' / ', second_num, ' = ', answer)

    elif Operator == '//' or Operator == '商':
        answer = quotient(first_num, second_num)
        print(first_num, ' // ', second_num, ' = ', answer)

    elif Operator == '%' or Operator == '余':
        answer = mod(first_num, second_num)
        print(first_num, ' % ', second_num, ' = ', answer)

    elif Operator == '**' or Operator == '幂':
        answer = power(first_num, second_num)
        print(first_num, ' ** ', second_num, ' = ', answer)
